<?php
/**
 * 卡片种类
 * User: Acer
 * Date: 2022/7/8
 * Time: 21:58
 */
namespace app\card\controller;

use app\core\MyController;
use app\card\service\CardTypeService;
class CardType extends MyController{
    protected  $noNeedAction = []; // 不需要校验控制器，通道
    // 操作前置
    protected $beforeActionList = ['my_initialize'];
    // 操作前置方法
    public function my_initialize(){
//        $this->is_admin();  // 权限检查

    }

    /**
     * 新增卡片种类
     */
    public function add_card_type(){
        $data = input();
        if(empty($data['card_name'])|| empty($data['type'])) json_err( -201);
        // 状态
        if(!isset($data['state'])) $data['state'] = 0;
        $res = (new CardTypeService())->s_add_type($data);
        if($res) _action_result(200,[],'操作成功！');
        json_err( -205);
    }

    // 修改卡片种类信息
    public function modify_card_type(){
        $data = input();
        if(empty($data['card_name']) || empty($data['ct_id']) || empty($data['type'])) json_err( -201);
        // 状态
        if(!isset($data['state'])) $data['state'] = 0;
        (new CardTypeService())->s_modify_card_type($data);
         _action_result(200,[],'操作成功！');
    }
    // 获取list
    public function  get_card_type_list(){
        $data = input();
        // 页数
        if(!isset($data['page']))  json_err( -201);
        // 当前页数
        if(!isset($data['page_number'])) $data['page_number'] = 10;

        // 查询
        $like =[];
        // 卡片种类名称
        if( isset($data['card_name']) && $data['card_name'] ) {
            $like = [
                'card_name'=>$data['card_name']
            ];
        }
        $res = (new CardTypeService())->s_card_type_list($data['page'],$data['page_number'] > 0 ? $data['page_number'] : 1,$like);
        if($res) _action_result(200,$res,'操作成功！');
        json_err( -205);
    }

    // 修改状态
        public function state_card_type(){
        $data = input();
        if(empty($data['ct_id'])) json_err( -201);
        $res = (new CardTypeService())->s_state_card_type($data);
        if($res) _action_result(200,[],'操作成功！');
        json_err( -205);
    }


}